package wish

import (
	"reward-server/forms/request"
	"reward-server/handler"
	"reward-server/service"
	"reward-server/utils"

	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

// 获取当前合约所有者
func GetOwner(c *gin.Context) {

	addr, err := service.NewWishService().Owner()
	if err != nil {
		utils.GinReply(c, "操作失败", 500, gin.H{})
		return
	}
	utils.GinReply(c, "操作成功", 200, gin.H{"addr": addr})
	return
}

// 获取许愿池操作人数
func GetNumber(c *gin.Context) {

	number, err := service.NewWishService().Number()
	if err != nil {
		utils.GinReply(c, "操作失败", 500, gin.H{})
		return
	}
	utils.GinReply(c, "操作成功", 200, gin.H{"number": number})
	return
}

// 获取钱包剩余金额
func GetBalance(c *gin.Context) {

	var req request.WishReq
	if err := c.ShouldBindQuery(&req); err != nil {
		zap.S().Errorf("验证数据出错:%v", err)
		handler.HandleValidator(err, c)
		return
	}
	balance, err := service.NewWishService().GetBalance(req.Addr)
	if err != nil {
		utils.GinReply(c, "操作失败", 500, gin.H{})
		return
	}
	utils.GinReply(c, "操作成功", 200, gin.H{"balance": balance})
	return
}
func Withdraw(c *gin.Context) {

	balance, err := service.NewWishService().Withdraw()
	if err != nil {
		utils.GinReply(c, "操作失败", 500, gin.H{})
		return
	}
	utils.GinReply(c, "操作成功", 200, gin.H{"balance": balance})
	return
}
